package info.fernandoguillen.javadb2.tests;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

import org.apache.log4j.Logger;

import com.ibm.as400.access.AS400;
import com.ibm.as400.access.AS400JPing;


/**
 * <p>
 * </p>
 * 
 * @internal_author fguillen.mail@gmail.com
 * @date 15/04/2008
 *
 */
public class TestJTOpenPingMain {
	private static final Logger log = 
		Logger.getLogger( TestJTOpenPingMain.class );

	/**
	 * <p>
	 * 
	 * </p>
	 * @date: 15/04/2008
	 * @author: fguillen.mail@gmail.com
	 *
	 * @param args
	 */
	public static void main(String[] args) {
		if( log.isDebugEnabled() ) {
			log.debug( "main:INI" );
		}

		if( args.length != 1 ){
			log.error( "use it with one argument: ipServer" );
			System.exit(1);
		}
		
		String ipServer = args[0];
		
		if( log.isDebugEnabled() ) {
			log.debug( "ipServer:" + ipServer );
		}
		
		//
		// cargamos hash con todos los servicios a ejecutar.
		//
		HashMap<String , Integer> servicios = new HashMap<String, Integer>();
		servicios.put( "AS400.FILE", new Integer( AS400.FILE ) );
		servicios.put( "AS400.DATABASE", new Integer( AS400.DATABASE ) );
		servicios.put( "AS400.COMMAND", new Integer( AS400.COMMAND ) );
		servicios.put( "AS400.SIGNON", new Integer( AS400.SIGNON ) );
		servicios.put( "AS400.CENTRAL", new Integer( AS400.CENTRAL ) );
		servicios.put( "AS400.DATAQUEUE", new Integer( AS400.DATAQUEUE ) );
		servicios.put( "AS400.RECORDACCESS", new Integer( AS400.RECORDACCESS ) );
		servicios.put( "AS400.PRINT", new Integer( AS400.PRINT ) );
		
		//
		// iniciamos objeto AS400Ping
		//
		AS400JPing pingObj = new AS400JPing( ipServer );
		
		//
		// ejecuto pings
		//
		Set<String> keys = servicios.keySet();
		for (Iterator iter = keys.iterator(); iter.hasNext(); ) {
			String key = (String) iter.next();
			int servicio = servicios.get( key ).intValue();
			
			if (pingObj.ping( servicio )) {
				log.info( key + ":SUCCESS");
			} else {
				log.info( key + ":FAILED" );
			}
			
		}
		
		if( log.isDebugEnabled() ) {
			log.debug( "main:END" );
		}
	}

}
